var vm = new Vue({
    el:'#cart',
    data:{
        list:[
            {pic:'鱼.jpg',name:'秋刀鱼/斤',price:35.00,count:1},
            {pic:'鱼.jpg',name:'鲜大带鱼/条',price:45.00,count:1},
            {pic:'鱼.jpg',name:'皮皮虾/斤',price:85.00,count:1},
        ]
    },
    methods:{
        sub(item){
            if(item.count>1){
                item.count--;
            }
        },
        add(item){
            if(item.count<5){
                item.count++;
            }
        },
        clean(){
            this.list = [];
        }
    },
    computed:{
        sum(){
            var sum = 0;
            this.list.forEach((item)=>{
                sum += item.count;
            })
            return sum;
        },
        total(){
            var sum = 0;
                this.list.forEach((item)=>{
                sum += item.count * item.price;
                })
            return sum;
        }
    }
})